<template>
	<!-- 大客户信息弹框 -->
	<div>
    <!-- 搜索 -->
    <TopFilter
		ref="conditionFilter"
		:list="topFilterInit"
		:cols="3"
		labelWidth="100"
		@filterChange="changeHandle"
		@onCollapse="collapseHandle"
	/>
	<!-- table -->
	<FilterTable
		ref="table"
		height="230"
		:columns="columns"
		:selectionType="selectType"
		:fetchapi="fetchapi"
		:isSelectColumn="isSelectColumn"
		:defaultSelections="defaultSelectionsList"
		:params="fetchParams"
		:datakey="'records'"
		:onRowSelectChange="selectChange"
        columnsRef="cms-common_clue_dealerList_01"

		:onColumnsChange="columns => this.columns = columns"/>
		
		<div class="dialogBottmView">
			<el-button @click="closeDialog">取 消</el-button>
			<el-button @click="saveDialog" :loading="btnLoding" type="primary">确定</el-button>
		</div>
	</div>
</template>

<script>
	import { dictionary } from '@/utils/dictMixin';
	import { region } from '@/api/cms-common/region';//行政区域
	import { getDealerClueList } from '@/api/cms-api/customerManage/clue/createClue';//大客户线索管理
	import { formatdateByDay } from '@/utils';
	export default {
		name: 'customerCommonSelect',
		mixins: [dictionary,region],
		components: {},
		props: {
			submit: {
				type: String,
				default: '确定'
			},
			selectType:{
				type: String,
				default: 'multiple'
			},
			isSelectColumn:{
				type: Boolean,
				default: true
			},
			defaultSelections:{
				type: [String,Array],
				default: ''
			}
		},
		data() {
			return {
				btnLoding:false,
				topFilterInit:this.topFilterInitFun(),
				fetchapi: getDealerClueList,
				fetchParams:{},  //参数
				columns:this.creatHeader(),
				initDealerData:{},
				selectedRows: [],
				defaultSelectionsList: [],
			};
		},
		mounted() {
			this.BaseTable = this.$refs.table.$refs.pageTable;
		},
		methods: {
			//搜索数据
			topFilterInitFun(){
				return [
					{ type: 'INPUT',	label: '客户公司名称',	fieldName: 'customerName', placeholder: '请输入',initialValue: '' },
					{ type: 'SELECT',	label: '客户类型',		fieldName: 'customerType',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('2506') },
					{ type: 'SELECT',	label: '客户性质',		fieldName: 'customerProperty',   placeholder: '请选择', initialValue: "", itemList:  this.createDictList('2534') },
					{ type: 'SELECT',	label: '省份',			fieldName: 'customerProvince',  placeholder: '请选择',  initialValue: '',itemList: this.createRegionList()},
					{ type: 'SELECT',	label: '客户状态',		fieldName: 'customerStatus',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('2507') },
					{ type: 'SELECT',	label: '客户来源',		fieldName: 'customerSource',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('2508') },
					{ type: 'INPUT',	label: '客户关键联系人',fieldName: 'keyLinkMan', placeholder: '请输入',initialValue: '' },
					{ type: 'INPUT',	label: '联系电话',		fieldName: 'linkPhone', placeholder: '请输入',initialValue: '' }
				];
			},
			//搜索获取数据
			changeHandle(val){
				this.fetchParams=Object.assign({},val);
			},
			selectChange(rows){
				if(this.selectType === "single"){
					this.selectedRows = rows[0];
				}else{
					this.selectedRows = rows;
				}
			},
			closeDialog(){
				this.$emit('close');
			},
			saveDialog(){
				if(this.selectedRows.length == 0){
					this.$notify.warning({title: '提示信息',message:'请选择任意一条数据！'});
					return;
				}
				this.btnLoding = true;
				this.$emit('save',this.selectedRows);
			},
			//table表头和数据源
			creatHeader(){
				return [
					{
						title: '序号',
						dataIndex: 'index',
						width: 80,
						sorter: true,
						render: props => {
							// 待完善
							// //如果是空的，直接跳过
							// if(!this.defaultSelections){
							// 	return <span>{props.row.index + 1}</span>;
							// }
							// //如果是list，循环判断
							// if(Array.isArray(this.defaultSelections)){
							// 	this.defaultSelections.forEach(item => {
							// 		if(typeof item === 'string'){
							// 			if(props.row.clueId === item){
							// 				//如果是字符，
							// 				this.defaultSelectionsList.push(props.row);
							// 			}else{
							// 				this.defaultSelectionsList.push(item);
							// 			}
							// 		}
							// 	});
							// }else if(props.row.clueId === this.defaultSelections){
							// 	//如果是字符，
							// 	this.defaultSelectionsList = [props.row];
							// }
							return <span>{props.row.index + 1}</span>;
						}
					},
					{ title: '客户公司名称',  dataIndex: 'customerName', sorter: true},
					{ title: '客户类型', dataIndex: 'customerType', sorter: true,
						render: props => {
							return <span>{this.createDictText(props.row.customerType, '2506')}</span>;
						}
					},
					{ title: '客户性质', dataIndex: 'customerProperty', sorter: true ,
						render: props => {
							return <span>{this.createDictText(props.row.customerProperty, '2534')}</span>;
						}
					},
					{ title: '所在省', dataIndex: 'customerProvince', sorter: true ,
						render: props => {
							return <span>{this.createRegionText(props.row.customerProvince)}</span>;
						}
					},
					{ title: '所在市', dataIndex: 'customerCity', sorter: true ,
						render: props => {
							return <span>{this.createRegionText(props.row.customerCity)}</span>;
						}
					},
					{ title: '所在县/区', dataIndex: 'customerDistrict', sorter: true ,
						render: props => {
							return <span>{this.createRegionText(props.row.customerDistrict)}</span>;
						}
					},
					{ title: '详细地址', dataIndex: 'customerAddress', sorter: true },
					{ title: '区域经理',  dataIndex: 'majorSbuManagerName',   sorter: true },
					{ title: '指定经销商',   dataIndex: 'dealerName', sorter: true},
					{ itle: '客户状态', dataIndex: 'customerStatus', sorter: true,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.customerStatus, '2507')}</span>;
						}
					},
					{ title: '客户来源', dataIndex: 'customerSource', sorter: true ,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.customerSource, '2508')}</span>;
						}
					},
					{ title: '所属行业分类', dataIndex: 'industryCategory', sorter: true ,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.industryCategory, '2510')}</span>;
						}
					},
					{ title: '行业地位', dataIndex: 'industryStatus', sorter: true ,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.industryStatus, '2511')}</span>;
						}
					},
					{ title: '购车用途', dataIndex: 'buyPurpose', sorter: true,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.buyPurpose, '2513')}</span>;
						}
					},
					{ title: '预计采购日期', dataIndex: 'estimatePurchaseDate', sorter: true,
						render: props =>{
							return <span>{ formatdateByDay(props.row.estimatePurchaseDate) }</span>
						}
					},
					{ title: '客户采购方式', dataIndex: 'purchaseMode', sorter: true ,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.purchaseMode, '2512')}</span>;
						}
					},
					{ title: '预算来源', dataIndex: 'budgetSource', sorter: true ,
						render: props => {
							//编码转汉字
							return <span>{this.createDictText(props.row.budgetSource, '2514')}</span>;
						}
					},
					{ title: '客户关键联系人', dataIndex: 'keyLinkMan', sorter: true },
					{ title: '联系方式', dataIndex: 'linkPhone', sorter: true }
				]
			},
			collapseHandle() {
				this.$nextTick(() => {
					this.BaseTable.EXECUTE_RESET_HEIGHT();
				});
			}
		},

	};
</script>

<style lang="less" scoped>
</style>
